using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Demo.Calendar.Code;
namespace Demo.Calendar.Features.AddCalendarList
{

    [Guid("8fa5c174-1c5a-4506-9204-7ffaf3a73dcc")]
    public class AddCalendarListEventReceiver : SPFeatureReceiver
    {
        const string columnGroup = "Demo";

        const string ctName = "RollUpCalendarContentType";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            using (SPWeb spWeb = properties.GetWeb() as SPWeb)
            {
                if ((spWeb.Lists.TryGetList("RollupCalendar") == null))
                {
                    //create the list if it dosen't to exist
                    CreatecalendarList(spWeb);
                }
            }
        }
        private void CreatecalendarList(SPWeb web)
        {
            Guid newListGuid = web.Lists.Add("RollupCalendar", "Custom Calendar.",
            SPListTemplateType.Events);
            SPList newList = web.Lists[newListGuid];
            newList.ContentTypesEnabled = true;
            var cal = web.Site.RootWeb.ContentTypes[ctName];
            newList.ContentTypes.Add(cal);
            newList.ContentTypes.Delete(newList.ContentTypes["Event"].Id);
            newList.Update();
            var view = newList.DefaultView;
            //add all view fields here
             SPContentType ct = cal as SPContentType;
            SPField field = ct.Fields.GetField("MilCategory");
            view.ViewFields.Add(field);

            view.Update();





        }

    }
}
